<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>

<script type="text/javascript">
	var edit_form_panel = Ext.create("Ext.form.Panel", {
		url : "edit.htm",
		buttonAlign : "center",
		bodyStyle : "padding: 10px;",
		defaultType : "textfield",
		layout : "form",
		items : [ {
			xtype : "fieldcontainer",
			layout : "column",
			fieldLabel : "类型",
			items : [ {
				xtype : "radiogroup",
				labelStyle : "text-align:right;",
				value : 1,
				items : [ {
					boxLabel : "还款",
					name : "pos.type",
					inputValue : "还款",
					readOnly : true
				}, {
					boxLabel : "消费",
					
					name : "pos.type",
					inputValue : "消费",
					readOnly : true
				} ],
				allowBlank : false
			} ]
		}, {
			fieldLabel : "金额",
			name : "pos.money",
			xtype : "numberfield",
			allowBlank : false
		}, {
			xtype : "fieldcontainer",
			layout : "column",
			id:'tt1',
			fieldLabel : "机器费率",
			items : [ {
				name : "pos.rate",
				xtype : "numberfield",
				listeners : {
					render : function(obj) {
						var font = document.createElement("font");
						font.setAttribute("color", "red");
						var redStar = document.createTextNode('%');
						font.appendChild(redStar);
						obj.el.dom.parentNode.appendChild(font);
					}
				}
			} ]
		}, {
			id:'tt2',
			fieldLabel : "转账手续费",
			name : "pos.rate_money",
			xtype : "numberfield"
		}, {
			fieldLabel : "卡内余额",
			name : "pos.money_remain",
			xtype : "numberfield",
			allowBlank : false
		}, {
			fieldLabel : "交易地点",
			name : "pos.address",
			xtype : "textfield",
			allowBlank : false
		}, {
			fieldLabel : "备注",
			name : "pos.note",
			xtype : "textareafield"
		}, {
			fieldLabel : "id",
			name : "pos.kid",
			hidden : true
		}

		],
		buttons : [ {
			text : "保存",
			formBind : true, //only enabled once the form is valid
			disabled : true,
			handler : function() {
				var form = this.up("form").getForm();
				if (form.isValid()) {
					form.submit({
						waitMsg : "保存中...",
						success : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
							edit_form_panel_win.close();
							dataStore.load();
							window.location.reload(true);
						},
						failure : function(form, action) {
							Ext.Msg.alert("提示", action.result.tip.msg);
						}
					});
				}
			}
		} ]
	});

	var edit_form_panel_win = Ext.create("Ext.Window", {
		title : "流水修改",
		closeAction : "hide",
		items : edit_form_panel
	});

	function myEdit(kid) {
		Ext.Ajax.request({
			url : "edit_form.htm?kid=" + kid,
			success : function(response) {
				var json = Ext.util.JSON.decode(response.responseText);
				edit_form_panel.getForm().reset();
				edit_form_panel.getForm().setValues(json);
				edit_form_panel_win.show();
				
				console.log(json);
				if(json["pos.type"]=='还款'){
					Ext.getCmp('tt1').hide();
					$('#tt2-labelEl').html('转账手续费');
				}else{
					Ext.getCmp('tt1').show();
					$('#tt2-labelEl').html('费率成本');
				}
			},
			failure : function(response) {
				Ext.Msg.alert("提示", "操作失败!");
			}
		});
	}//#myEdit
</script>
